package com.laowang.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.TbProxyRebate;
import com.laowang.project.system.service.TbProxyRebateService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 代理返利Controller
 * 
 * @author laowang
 * @date 2023-01-16
 */
@Api(tags = "代理返利接口")
@RestController
@RequestMapping("/rebate")
public class TbProxyRebateController extends BaseController {

    @Autowired
    private TbProxyRebateService tbProxyRebateService;

    @ApiOperation(value = "小程序端 查询代理返利列表",notes = "")
    @GetMapping("/wxApp/list")
    public AjaxResult wxAppList() {
        List<TbProxyRebate> list = tbProxyRebateService.selectTbProxyRebateList(null);
        return AjaxResult.success("操作成功",list);
    }


    /**
     * 查询代理返利列表
     */
    @ApiOperation(value = "后台 查询代理返利列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:rebate:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbProxyRebate tbProxyRebate) {
        startPage();
        List<TbProxyRebate> list = tbProxyRebateService.selectTbProxyRebateList(tbProxyRebate);
        return getDataTable(list);
    }
    
    /**
     * 导出代理返利列表
     */
    @ApiOperation(value = "后台导出代理返利列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:rebate:export')")
    @Log(title = "代理返利", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbProxyRebate tbProxyRebate) {
        List<TbProxyRebate> list = tbProxyRebateService.selectTbProxyRebateList(tbProxyRebate);
        ExcelUtil<TbProxyRebate> util = new ExcelUtil<TbProxyRebate>(TbProxyRebate.class);
        return util.exportExcel(list, "rebate");
    }

    /**
     * 获取代理返利详细信息
     */
    @ApiOperation(value = "后台获取代理返利详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('system:rebate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tbProxyRebateService.selectTbProxyRebateById(id));
    }

    /**
     * 新增代理返利
     */
    @ApiOperation(value = "后台新增代理返利",notes = "")
    @PreAuthorize("@ss.hasPermi('system:rebate:add')")
    @Log(title = "代理返利", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbProxyRebate tbProxyRebate) {
        return toAjax(tbProxyRebateService.insertTbProxyRebate(tbProxyRebate));
    }

    /**
     * 修改代理返利
     */
    @ApiOperation(value = "后台修改代理返利",notes = "")
    @PreAuthorize("@ss.hasPermi('system:rebate:edit')")
    @Log(title = "代理返利", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbProxyRebate tbProxyRebate) {
        return toAjax(tbProxyRebateService.updateTbProxyRebate(tbProxyRebate));
    }

    /**
     * 删除代理返利
     */
    @ApiOperation(value = "后台删除代理返利",notes = "")
    @PreAuthorize("@ss.hasPermi('system:rebate:remove')")
    @Log(title = "代理返利", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbProxyRebateService.deleteTbProxyRebateByIds(ids));
    }
}
